<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //倒计时
      //现在时间 距离下周二上课有多久
      //获取两个时间对象的时间差 两个时间戳的差值
      let body = document.querySelector('body')
      function fn() {
        var date1 = new Date().getTime()
        var date2 = new Date(2022, 7, 16, 8, 25).getTime()
        var time_step = date2 - date1
        var Seconds = parseInt(time_step / 1000)
        var day = parseInt(Seconds / 3600 / 24)
        var hour = parseInt((time_step - day * 24 * 3600 * 1000) / 3600000)
        var min = parseInt(
          (time_step - day * 24 * 3600 * 1000 - hour * 3600000) / 60000
        )
        var seconds = parseInt(
          (time_step - day * 24 * 3600 * 1000 - hour * 3600000 - min * 60000) /
            1000
        )
        body.innerHTML = `距离下周二上课还有：${day}天${hour}时${min}分${seconds}秒`
      }
      setInterval(fn, 1000)
    </script>
  </body>
</html>
